package test;

import org.jing.core.lang.data.Carrier;
import org.jing.core.lang.data.FileContent;

/**
 * Description: <br>
 *
 * @author bks <br>
 * @since 2020-07-17 <br>
 */
class Demo4Json {
    private Demo4Json() {
        test();
    }

    private void parseJson() {
        try (
            FileContent reader = FileContent.readFile("temp/temp.json")
        ) {
            String json = reader.asString();
            Carrier jsonC = Carrier.parseJson(json);
            System.out.println(jsonC);
        }
    }

    private void test() {
        try (
            FileContent reader = FileContent.readFile("temp/temp2.json");
        ) {
            Carrier tempC = new Carrier();
            String json = reader.asString();
            int limit = 1000;
            long start = System.currentTimeMillis();
            for (int i$ = 0; i$ < limit; i$ ++) {
                Carrier.parseJson(json);
                System.out.printf("%s/%s%n", (i$ + 1), limit);
            }
            long end = System.currentTimeMillis();
            System.out.println("cost: " + (end - start));
        }
    }

    private void createJson() {
        try (
            FileContent reader = FileContent.readFile("temp/temp.json");
            FileContent writer = new FileContent()
        ) {
            Carrier tempC = new Carrier();
            String json = reader.asString();
            int limit = 1000;
            long start = System.currentTimeMillis();
            for (int i$ = 0; i$ < limit; i$ ++) {
                // Carrier.parseJson(json);
                tempC.addCarrier(Carrier.parseJson(json).setKey(String.valueOf((i$ + 1))));
                // System.out.printf("%s/%s%n", (i$ + 1), limit);
            }
            long end = System.currentTimeMillis();
            writer.add(tempC.asSimpleJson());
            writer.write("temp/temp2.json");
            System.out.println("cost: " + (end - start));
        }
    }

    public static void main(String[] args) {
        new Demo4Json();
    }
}
